package com.test.daily.leetcode.y2022.m07.day0705.v10;

import java.util.TreeMap;
import java.util.TreeSet;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/7/5 下午 10:21
 * @version: 1.0
 */
public class Solution {
    public static class MyCalendar{
        public TreeSet<int[]> booked;
        public MyCalendar(){
            booked = new TreeSet<>((a, b) ->a[0] -b[0]);
        }
        public boolean book(int start, int end){
            if(booked.isEmpty()){
                booked.add(new int[]{start, end});
                return true;
            }
            int[] tmp = new int[]{end, 0};
            int[] arr = booked.ceiling(tmp);
            if(arr == booked.first() || booked.lower(tmp)[1] < start){
                booked.add(new int[]{start,end});
                return true;
            }
            return false;
        }
    }
}
